from typedef cimport *
from base cimport *
from adapter cimport *

cdef extern from 'stdafx.h':
    DEF kMCount = 9

    ctypedef struct fPoint:
        float fX
        float fY
        
    ctypedef struct fRect:
        float fLeft
        float fTop
        float fRight
        float fBottom

    ctypedef enum Direction:
        kUnknown_Direction = 0
        kCW_Direction = 1
        kCCW_Direction = 2

    ctypedef enum AddPathMode:
        kAppend_AddPathMode = 0
        kExtend_AddPathMode = 1

    ctypedef struct IxForm:
        float fMat[kMCount]

    BOOL Decoder_Stb_SCreateInstance(IObjRef **ppObj)
    BOOL Render_Gdi_SCreateInstance(IObjRef **ppObj)
    BOOL Render_Skia_SCreateInstance(IObjRef **ppObj)
    BOOL Log4z_SCreateInstance(IObjRef **ppObj)
    BOOL Resp_7zip_SCreateInstance(IObjRef ** ppObj)
    BOOL Resp_Zip_SCreateInstance(IObjRef ** ppObj)
    BOOL Script_Lua_SCreateInstance(IObjRef ** ppObj)
    BOOL TaskLoop_SCreateInstance(IObjRef **ppObj)
    BOOL Translator_SCreateInstance(IObjRef **ppObj)
    BOOL Ipc_SCreateInstance(IObjRef **ppIpcFactory);

    ctypedef struct IResProviderMgrVtbl:
        void AddResProvider(IResProviderMgr* this, IResProvider * pResProvider, LPCTSTR pszUidef)
        void RemoveResProvider(IResProviderMgr* this, IResProvider * pResProvider)
        void RemoveAll(IResProviderMgr* this)
        IResProvider* GetHeadResProvider(IResProviderMgr* this)
        IResProvider* GetTailResProvider(IResProviderMgr* this)
        void SetFilePrefix(IResProviderMgr* this, LPCTSTR pszFilePrefix)
        BOOL HasResource(IResProviderMgr* this, LPCTSTR pszType, LPCTSTR pszResName)
        HICON LoadIcon(IResProviderMgr* this, LPCTSTR pszResName, int cx, int cy, BOOL bFromFile)
        HCURSOR LoadCursor(IResProviderMgr* this, LPCTSTR pszResName, BOOL bFromFile)
        HBITMAP LoadBitmap(IResProviderMgr* this, LPCTSTR pszResName, BOOL bFromFile)
        IBitmapS* LoadImage(IResProviderMgr* this, LPCTSTR pszType, LPCTSTR pszResName)
        IImgX* LoadImgX(IResProviderMgr* this, LPCTSTR pszType, LPCTSTR pszResName)
        size_t GetRawBufferSize(IResProviderMgr* this, LPCTSTR pszType, LPCTSTR pszResName)
        BOOL GetRawBuffer(IResProviderMgr* this, LPCTSTR pszType, LPCTSTR pszResName, LPVOID pBuf, size_t size)

    ctypedef struct IResProviderMgr:
        IResProviderMgrVtbl* lpVtbl

    ctypedef struct IImgDecoderFactoryVtbl:
        BOOL CreateImgX(IImgDecoderFactory* this, IImgX * *ppImgDecoder)
        HRESULT SaveImage(IImgDecoderFactory* this, BYTE * pBits, int nWid, int nHei, LPCWSTR pszFileName, LPVOID pFormat)
        LPCWSTR GetDescription(IImgDecoderFactory* this)

    ctypedef struct IImgDecoderFactory:
        IImgDecoderFactoryVtbl* lpVtbl

    ctypedef struct IRenderFactoryVtbl:
        IImgDecoderFactory* GetImgDecoderFactory(IRenderFactory* this)
        void SetImgDecoderFactory(IRenderFactory* this, IImgDecoderFactory * pImgDecoderFac)
        BOOL CreateRenderTarget(IRenderFactory* this, IRenderTarget * *ppRenderTarget, int nWid, int nHei)
        BOOL CreateFont(IRenderFactory* this, IFontS * *ppFont, const LOGFONT *lf)
        BOOL CreateBitmap(IRenderFactory* this, IBitmapS * *ppBitmap)
        BOOL CreateRegion(IRenderFactory* this, IRegionS * *ppRgn)
        HRESULT CreateBlurMaskFilter(IRenderFactory* this, float radius, BlurStyle style, BlurFlags flag, IMaskFilter **ppMaskFilter)
        HRESULT CreateEmbossMaskFilter(IRenderFactory* this, float direction[3], float ambient, float specular, float blurRadius, IMaskFilter **ppMaskFilter)
        BOOL CreatePath(IRenderFactory* this, IPathS * *ppPath)
        BOOL CreatePathEffect(IRenderFactory* this, REFGUID guidEffect, IPathEffect **ppPathEffect)
        BOOL CreatePathMeasure(IRenderFactory* this, IPathMeasure * *ppPathMeasure)

    ctypedef struct IRenderFactory:
        IRenderFactoryVtbl* lpVtbl

    ctypedef struct IRenderTargetVtbl:
        HRESULT CreatePen(IRenderTarget* this, int iStyle, COLORREF cr, int cWidth, IPenS**ppPen)
        HRESULT CreateSolidColorBrush(IRenderTarget* this, COLORREF cr, IBrushS**ppBrush)
        HRESULT CreateBitmapBrush(IRenderTarget* this, IBitmapS* pBmp, TileMode xtm, TileMode ytm, IBrushS**ppBrush)
        HRESULT CreateRegion(IRenderTarget* this, IRegionS**ppRegion)
        HRESULT Resize(IRenderTarget* this, SIZE sz)
        HRESULT OffsetViewportOrg(IRenderTarget* this, int xOff, int yOff, LPPOINT lpPoint)
        HRESULT GetViewportOrg(IRenderTarget* this, LPPOINT lpPoint)
        HRESULT SetViewportOrg(IRenderTarget* this, POINT pt)
        HRESULT PushClipRect(IRenderTarget* this, LPCRECT pRect, UINT mode)
        HRESULT PushClipRegion(IRenderTarget* this, IRegionS* pRegion, UINT mode)
        HRESULT PopClip(IRenderTarget* this)
        HRESULT ExcludeClipRect(IRenderTarget* this, LPCRECT pRc)
        HRESULT IntersectClipRect(IRenderTarget* this, LPCRECT pRc)
        HRESULT SaveClip(IRenderTarget* this, int*pnState)
        HRESULT RestoreClip(IRenderTarget* this, int nState)
        HRESULT GetClipRegion(IRenderTarget* this, IRegionS**ppRegion)
        HRESULT GetClipBox(IRenderTarget* this, LPRECT prc)
        HRESULT DrawText(IRenderTarget* this, LPCTSTR pszText, int cchLen, LPRECT pRc, UINT uFormat)
        HRESULT MeasureText(IRenderTarget* this, LPCTSTR pszText, int cchLen, SIZE*psz)
        HRESULT TextOut(IRenderTarget* this, int x, int y, LPCTSTR lpszString, int nCount)
        HRESULT DrawRectangle(IRenderTarget* this, LPCRECT pRect)
        HRESULT FillRectangle(IRenderTarget* this, LPCRECT pRect)
        HRESULT FillSolidRect(IRenderTarget* this, LPCRECT pRect, COLORREF cr)
        HRESULT DrawRoundRect(IRenderTarget* this, LPCRECT pRect, POINT pt)
        HRESULT FillRoundRect(IRenderTarget* this, LPCRECT pRect, POINT pt)
        HRESULT FillSolidRoundRect(IRenderTarget* this, LPCRECT pRect, POINT pt, COLORREF cr)
        HRESULT ClearRect(IRenderTarget* this, LPCRECT pRect, COLORREF cr)
        HRESULT InvertRect(IRenderTarget* this, LPCRECT pRect)
        HRESULT DrawEllipse(IRenderTarget* this, LPCRECT pRect)
        HRESULT FillEllipse(IRenderTarget* this, LPCRECT pRect)
        HRESULT FillSolidEllipse(IRenderTarget* this, LPCRECT pRect, COLORREF cr)
        HRESULT DrawArc(IRenderTarget* this, LPCRECT pRect, float startAngle, float sweepAngle, BOOL useCenter)
        HRESULT FillArc(IRenderTarget* this, LPCRECT pRect, float startAngle, float sweepAngle)
        HRESULT DrawLines(IRenderTarget* this, LPPOINT pPt, size_t nCount)
        HRESULT GradientFill(IRenderTarget* this, LPCRECT pRect, BOOL bVert, COLORREF crBegin, COLORREF crEnd, BYTE byAlpha)
        HRESULT GradientFillEx(IRenderTarget* this, LPCRECT pRect, const POINT*pts, COLORREF*colors, float*pos, int nCount, BYTE byAlpha)
        HRESULT GradientFill2(IRenderTarget* this, LPCRECT pRect, GradientType type, COLORREF crStart, COLORREF crCenter, COLORREF crEnd, float fLinearAngle, float fCenterX, float fCenterY, int nRadius, BYTE byAlpha)
        HRESULT DrawIconEx(IRenderTarget* this, int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, UINT diFlags)
        HRESULT DrawBitmap(IRenderTarget* this, LPCRECT pRcDest, const IBitmapS*pBitmap, int xSrc, int ySrc, BYTE byAlpha)
        HRESULT DrawBitmapEx(IRenderTarget* this, LPCRECT pRcDest, const IBitmapS*pBitmap, LPCRECT pRcSrc, UINT expendMode, BYTE byAlpha)
        HRESULT DrawBitmap9Patch(IRenderTarget* this, LPCRECT pRcDest, const IBitmapS*pBitmap, LPCRECT pRcSrc, LPCRECT pRcSourMargin, UINT expendMode, BYTE byAlpha)
        HRESULT BitBlt(IRenderTarget* this, LPCRECT pRcDest, IRenderTarget* pRTSour, int xSrc, int ySrc, DWORD dwRop)
        HRESULT AlphaBlend(IRenderTarget* this, LPCRECT pRcDest, IRenderTarget* pRTSrc, LPCRECT pRcSrc, BYTE byAlpha)
        IRenderObj* GetCurrentObject(IRenderTarget* this, OBJTYPE uType)
        HRESULT SelectDefaultObject(IRenderTarget* this, OBJTYPE objType, IRenderObj**pOldObj)
        HRESULT SelectObject(IRenderTarget* this, IRenderObj* pObj, IRenderObj**pOldObj)
        COLORREF GetTextColor(IRenderTarget* this)
        COLORREF SetTextColor(IRenderTarget* this, COLORREF color)
        void SetMaskFilter(IRenderTarget* this, IMaskFilter* pMaskFilter)
        IMaskFilter* GetMaskFilter(IRenderTarget* this)
        HDC GetDC(IRenderTarget* this, UINT uFlag)
        void ReleaseDC(IRenderTarget* this, HDC hdc, LPCRECT pRc)
        HRESULT SetTransform(IRenderTarget* this, const float matrix[9], float oldMatrix[9])
        HRESULT GetTransform(const IRenderTarget* this, float matrix[9])
        COLORREF GetPixel(IRenderTarget* this, int x, int y)
        COLORREF SetPixel(IRenderTarget* this, int x, int y, COLORREF cr)
        HRESULT PushClipPath(IRenderTarget* this, const IPathS*path, UINT mode, BOOL doAntiAlias)
        HRESULT DrawPath(IRenderTarget* this, const IPathS*path, IPathEffect*pathEffect)
        HRESULT FillPath(IRenderTarget* this, const IPathS*path)
        HRESULT SetXfermode(IRenderTarget* this, int mode, int*pOldMode)
        BOOL SetAntiAlias(IRenderTarget* this, BOOL bAntiAlias)
        BOOL GetAntiAlias(const IRenderTarget* this)

    ctypedef struct IRenderTarget: # (IObjRef)
        IRenderTargetVtbl* lpVtbl

    ctypedef struct IRenderObjVtbl:
        IRenderFactory* GetRenderFactory(IRenderObj* this)
        OBJTYPE ObjectType(IRenderObj* this)

    ctypedef struct IRenderObj:
        IRenderObjVtbl* lpVtbl

    ctypedef struct IFontSVtbl:
        const LOGFONT* LogFont(const IFontS* this)
        LPCTSTR FamilyName(const IFontS* this)
        int TextSize(const IFontS* this)
        BOOL IsBold(const IFontS* this)
        BOOL IsUnderline(const IFontS* this)
        BOOL IsItalic(const IFontS* this)
        BOOL IsStrikeOut(const IFontS* this)
        BOOL UpdateFont(IFontS* this, const LOGFONT*pLogFont)
        void SetProp(IFontS* this, IXmlNode* pXmlNode)

    ctypedef struct IFontS: # (IRenderObj)
        IFontSVtbl* lpVtbl

    ctypedef struct IBitmapSVtbl:
        HRESULT Init(IBitmapS* this, int nWid, int nHei, const LPVOID pBits)
        HRESULT Init2(IBitmapS* this, IImgFrame* pImgFrame)
        HRESULT LoadFromFile(IBitmapS* this, LPCTSTR pszFileName)
        HRESULT LoadFromMemory(IBitmapS* this, LPBYTE pBuf, size_t szLen)
        UINT Width(const IBitmapS* this)
        UINT Height(const IBitmapS* this)
        SIZE Size(const IBitmapS* this)
        LPVOID LockPixelBits(IBitmapS* this)
        void UnlockPixelBits(IBitmapS* this, LPVOID pBuf)
        const LPVOID GetPixelBits(const IBitmapS* this)
        HRESULT Clone(const IBitmapS* this, IBitmapS**ppClone)
        HRESULT Scale(const IBitmapS* this, IBitmapS**pOutput, int nScale, FilterLevel filterLevel)
        HRESULT Scale2(const IBitmapS* this, IBitmapS**pOutput, int nWid, int nHei, FilterLevel filterLevel)
        HRESULT Save(const IBitmapS* this, LPCWSTR pszFileName, const LPVOID pFormat)

    ctypedef struct IBitmapS: # (IRenderObj)
        IBitmapSVtbl* lpVtbl

    ctypedef struct IRegionSVtbl:
        void CombineRect(IRegionS* this, LPCRECT lprect, int nCombineMode)
        void CombineRgn(IRegionS* this, const IRegionS*pRgnSrc, int nCombineMode)
        void CombineRoundRect(IRegionS* this, LPCRECT lprect, POINT ptConner, int nCombineMode)
        void CombineEllipse(IRegionS* this, LPCRECT lprect, int nCombineMode)
        void CombinePolygon(IRegionS* this, const POINT*pts, int count, int nPolygonMode, int nCombineMode)
        BOOL PtInRegion(const IRegionS* this, POINT pt)
        BOOL RectInRegion(const IRegionS* this, LPCRECT lprect)
        void GetRgnBox(const IRegionS* this, LPRECT lprect)
        BOOL IsEmpty(const IRegionS* this)
        void Offset(IRegionS* this, POINT pt)
        void Clear(IRegionS* this)
        # BOOL IsEqual(const IRegionS* this, const IRegionS*testRgn)  # Method not available in SOUI5

    ctypedef struct IRegionS: # (IRenderObj)
        IRegionSVtbl* lpVtbl

    ctypedef struct IPathSVtbl:
        FillType getFillType(const IPathS* this)
        void setFillType(IPathS* this, FillType ft)
        # BOOL isInverseFillType(const IPathS* this)  # Method not available in SOUI5
        # void toggleInverseFillType(IPathS* this)  # Method not available in SOUI5
        # Convexity getConvexity(const IPathS* this)  # Method not available in SOUI5
        # void setConvexity(IPathS* this, Convexity c)  # Method not available in SOUI5
        # BOOL isConvex(const IPathS* this)  # Method not available in SOUI5
        # BOOL isOval(const IPathS* this, RECT* rect)  # Method not available in SOUI5
        void reset(IPathS* this)
        # void rewind(IPathS* this)  # Method not available in SOUI5
        BOOL isEmpty(const IPathS* this)
        # BOOL isFinite(const IPathS* this)  # Method not available in SOUI5
        # BOOL isLine(const IPathS* this, POINT line[2])  # Method not available in SOUI5
        # BOOL isRect(const IPathS* this, RECT* rect)  # Method not available in SOUI5
        # int countPoints(const IPathS* this)  # Method not available in SOUI5
        # fPoint getPoint(const IPathS* this, int index)  # Method not available in SOUI5
        # int getPoints(const IPathS* this, fPoint points[], int max)  # Method not available in SOUI5
        # int countVerbs(const IPathS* this)  # Method not available in SOUI5
        # int getVerbs(const IPathS* this, BYTE verbs[], int max)  # Method not available in SOUI5
        void getBounds(const IPathS* this, LPRECT prc)  # Fixed method signature
        void moveTo(IPathS* this, float x, float y)
        void rMoveTo(IPathS* this, float dx, float dy)
        void lineTo(IPathS* this, float x, float y)
        void rLineTo(IPathS* this, float dx, float dy)
        void quadTo(IPathS* this, float x1, float y1, float x2, float y2)
        void rQuadTo(IPathS* this, float dx1, float dy1, float dx2, float dy2)
        void conicTo(IPathS* this, float x1, float y1, float x2, float y2, float w)
        void rConicTo(IPathS* this, float dx1, float dy1, float dx2, float dy2, float w)
        void cubicTo(IPathS* this, float x1, float y1, float x2, float y2, float x3, float y3)
        void rCubicTo(IPathS* this, float x1, float y1, float x2, float y2, float x3, float y3)
        # void arcTo(IPathS* this, const RECT*oval, float startAngle, float sweepAngle, BOOL forceMoveTo)  # Method not available in SOUI5
        # void arcTo2(IPathS* this, float x1, float y1, float x2, float y2, float radius)  # Method not available in SOUI5
        void close(IPathS* this)
        # BOOL isRect2(const IPathS* this, BOOL* isClosed, Direction* direction)  # Method not available in SOUI5
        void addRect(IPathS* this, const RECT*rect, Direction dir)
        void addRect2(IPathS* this, float left, float top, float right, float bottom, Direction dir)
        void addOval(IPathS* this, const RECT*oval, Direction dir)
        void addCircle(IPathS* this, float x, float y, float radius, Direction dir)
        void addArc(IPathS* this, const RECT*oval, float startAngle, float sweepAngle)
        void addRoundRect(IPathS* this, const RECT*rect, float rx, float ry, Direction dir)
        void addRoundRect2(IPathS* this, float left, float top, float right, float bottom, float rx, float ry, Direction dir)
        void addPoly(IPathS* this, const POINT pts[], int count, BOOL close)
        # void addPath(IPathS* this, const IPathS*src, float dx, float dy, AddPathMode mode)  # Method not available in SOUI5
        # void reverseAddPath(IPathS* this, const IPathS*src)  # Method not available in SOUI5
        # void offset(IPathS* this, float dx, float dy)  # Method not available in SOUI5
        # void transform(IPathS* this, const IxForm*matrix)  # Method not available in SOUI5
        # BOOL getLastPt(const IPathS* this, POINT* lastPt)  # Method not available in SOUI5
        # void setLastPt(IPathS* this, float x, float y)  # Method not available in SOUI5
        void addString(IPathS* this, LPCTSTR pszText, int nLen, float x, float y, const IFontS*pFont)
        IPathInfo* approximate(IPathS* this, float acceptableError)

    ctypedef struct IPathS: # (IRenderObj)
        IPathSVtbl* lpVtbl

    ctypedef struct IPathInfoVtbl:
        int pointNumber(const IPathInfo* this)
        const float* data(const IPathInfo* this)

    ctypedef struct IPathInfo: # (IObjRef)
        IPathInfoVtbl* lpVtbl

    ctypedef struct IPenSVtbl:
        int GetWidth(const IPenS* this)
        void SetWidth(IPenS* this, int nWid)
        int GetStyle(const IPenS* this)
        void SetStyle(IPenS* this, int nStyle)
        COLORREF GetColor(const IPenS* this)
        void SetColor(IPenS* this, COLORREF cr)

    ctypedef struct IPenS: # (IRenderObj)
        IPenSVtbl* lpVtbl

    ctypedef struct IBrushSVtbl:
        pass

    ctypedef struct IBrushS: # (IRenderObj)
        IBrushSVtbl* lpVtbl

    ctypedef struct IPathEffectVtbl:
        void* GetRealPathEffect(IPathEffect* this)

    ctypedef struct IPathEffect: # (IObjRef)
        IPathEffectVtbl* lpVtbl

    ctypedef struct IImgFrameVtbl:
        BOOL GetSize(IImgFrame* this, UINT* pWid, UINT* pHei)
        const void* GetPixels(const IImgFrame* this)
        int GetDelay(IImgFrame* this)

    ctypedef struct IImgFrame: # (IObjRef)
        IImgFrameVtbl* lpVtbl

    ctypedef struct IImgXVtbl:
        int LoadFromMemory(IImgX* this, void*pBuf, size_t bufLen)
        int LoadFromFileW(IImgX* this, LPCWSTR pszFileName)
        int LoadFromFileA(IImgX* this, LPCSTR pszFileName)
        UINT GetFrameCount(IImgX* this)
        IImgFrame* GetFrame(IImgX* this, UINT iFrame)

    ctypedef struct IImgX: # (IObjRef)
        IImgXVtbl* lpVtbl

    ctypedef struct ISkinObjVtbl:
        void DrawByState2(const ISkinObj* this, IRenderTarget* pRT, LPCRECT rcDraw, DWORD dwState, BYTE byAlpha)
        void DrawByState(const ISkinObj* this, IRenderTarget* pRT, LPCRECT rcDraw, DWORD dwState)
        void DrawByIndex2(const ISkinObj* this, IRenderTarget* pRT, LPCRECT rcDraw, int iState, BYTE byAlpha)
        void DrawByIndex(const ISkinObj* this, IRenderTarget* pRT, LPCRECT rcDraw, int iState)
        SIZE GetSkinSize(const ISkinObj* this)
        int GetStates(const ISkinObj* this)
        BYTE GetAlpha(const ISkinObj* this)
        void SetAlpha(ISkinObj* this, BYTE byAlpha)
        void OnColorize(ISkinObj* this, COLORREF cr)
        int GetScale(const ISkinObj* this)
        ISkinObj* Scale(ISkinObj* this, int nScale)

    ctypedef struct ISkinObj: # (IObject)
        ISkinObjVtbl* lpVtbl

    enum ZipType:
        ZIPFILE = 0
        PEDATA = 1
        MEMORYDATA = 2

    struct _peInfo:
        HINSTANCE hInst
        LPCTSTR pszResName
        LPCTSTR pszResType

    struct _Memory:
        LPBYTE pByteBuffer
        DWORD dwByteCounts

    struct _ZIPRES_PARAM 'ZIPRES_PARAM':
        ZipType type
        IRenderFactory *pRenderFac
        LPCTSTR pszZipFile
        _peInfo peInfo
        _Memory Memory
        LPCSTR pszPsw
        LPCTSTR pszChildDir
        
    struct _ZIP7RES_PARAM 'ZIP7RES_PARAM':
        ZipType type
        IRenderFactory *pRenderFac
        LPCTSTR pszZipFile
        _peInfo peInfo
        LPCSTR pszPsw
        LPCTSTR pszChildDir
